package com.rui.study.algorithm.T_OutOfMemoryError;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2019-02-25 10:26
 **/
public class RuntimeConstantPool {

    public static void main(String[] args) {
//        List<String> list = new ArrayList<>();
//        int i = 0;
//        while (true) {
//            list.add(String.valueOf(i++).intern());
//        }

        RuntimeConstantPool rcp = new RuntimeConstantPool();
        rcp.internTest();
    }

    /**
     * intern()方法的测试
     */
    private void internTest() {
        String s1 = new String(new char[]{23,12,34});
        String s2 = new String(new char[]{23,12,34});
        System.out.println(s1.intern() == s1);
        System.out.println(s2.intern() == s1);
        System.out.println(s2.intern() == s2);
        System.out.println(s2.equals(s1));
    }
}
